﻿using Business.Base;
using Business.Base.DB;
using Business.Base.Model;
using Business.Base.Service;
using Business.NPSH;
using Pumptester.ExperimentForms.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Pumptester.ExperimentForms.Npsh
{
    public partial class ViewForm : BaseViewForm
    {
        

        public ViewForm()
        {
            InitializeComponent();
        }

        public ViewForm(Experiment experiment, BaseChartData chart,Form preForm):base(experiment,chart, preForm)
        {
            this.ChartDrawer = new NpshChart();
            InitializeComponent();
            this.dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            this.dataGridView.MergeColumnNames.Add("Column0");
            this.dataGridView.MergeColumnNames.Add("Column1");
            this.dataGridView.MergeColumnNames.Add("Column2");
            this.dataGridView.MergeColumnNames.Add("Column3");
            this.dataGridView.MergeColumnNames.Add("Column4");
            this.dataGridView.MergeColumnNames.Add("Column5");
            this.dataGridView.MergeColumnNames.Add("Column6");


            this.dataGridView.AddSpanHeader(0, 7, "转换前数据");

            this.dataGridView.MergeColumnNames.Add("Column7");
            this.dataGridView.MergeColumnNames.Add("Column8");

            this.dataGridView.AddSpanHeader(7, 2, "转换后数据");
        

        }

       


        

        private void LoadExperimentInfo()
        {
            NpshExperiment experiment = (NpshExperiment)Experiment;
            this.textBoxCode.Text = experiment.ExperimentCode;
            this.textBoxPumpName.Text = experiment.PumpName;
            //experiment.experimentName = this.textBoxPumpName.Text;
            this.textBoxProductModel.Text = experiment.PumpModel;
            this.textBoxPumpCode.Text = experiment.PumpCode;
            this.textBoxExperimentOwner.Text = experiment.ExperimentOwner;
            this.textBoxManufacturer.Text = experiment.Manufacturer;


            this.textBoxPumpName.Text = experiment.PumpName;

            this.textBoxProductModel.Text = experiment.PumpModel;
            this.textBoxPumpCode.Text = experiment.PumpCode;
            this.textBoxExperimentOwner.Text = experiment.ExperimentOwner;
            this.textBoxManufacturer.Text = experiment.Manufacturer;
            this.textBoxCustomer.Text = experiment.Customer;

            this.textRatedFlow.Text = experiment.PumpRatedFlow.ToString();
            this.textRatedHead.Text = experiment.PumpRatedHead.ToString();
            this.textRatedNpsh.Text = experiment.PumpRatedNpsh.ToString();
            this.textRatedPower.Text = (experiment.PumpRatedPower / 1000).ToString();
            //this.textCriticalNpsh.Text = experiment.DesignCriticalNpsh.ToString();
            this.textRatedEff.Text = experiment.MotorRatedEfficiency.ToString();
            this.textInDia.Text = (experiment.DInlet * 1000).ToString();
            this.textOutDia.Text = (experiment.DOutlet * 1000).ToString();


            for (int i = 0; i < experiment.RecordList.Count; i++)
            {
                NpshExperimentRecord record = (NpshExperimentRecord)experiment.RecordList[i];
                DataGridViewRow row = (DataGridViewRow)this.dataGridView.RowTemplate.Clone();

                record.ExperimentCode = this.Experiment.ExperimentCode;


                DataGridViewTextBoxCell idCell = new DataGridViewTextBoxCell();
                idCell.Value = i+1;
                idCell.Tag = false;

                DataGridViewTextBoxCell flowCell = new DataGridViewTextBoxCell();
                flowCell.Value = record.WorkingFlow.ToString("f6");
                flowCell.Tag = true;

                DataGridViewTextBoxCell speedCell = new DataGridViewTextBoxCell();
                speedCell.Value = record.WorkingSpeed.ToString("f6");
                speedCell.Tag = true;


                DataGridViewTextBoxCell presureInCell = new DataGridViewTextBoxCell();
                presureInCell.Value = record.PresureIn.ToString("f6");
                presureInCell.Tag = true;

                DataGridViewTextBoxCell presureOutCell = new DataGridViewTextBoxCell();
                presureOutCell.Value = record.PresureOut.ToString("f6");
                presureOutCell.Tag = true;




                DataGridViewTextBoxCell powerCell = new DataGridViewTextBoxCell();
                powerCell.Value = (record.WorkingPower / 1000.0).ToString("f6");
                powerCell.Tag = true;


                DataGridViewTextBoxCell temperatureCell = new DataGridViewTextBoxCell();
                temperatureCell.Value = record.Temperature.ToString("f6");
                temperatureCell.Tag = true;


                DataGridViewTextBoxCell npshCell = new DataGridViewTextBoxCell();
                npshCell.Value = record.Npsh.ToString("f6");
                npshCell.Tag = true;


                DataGridViewTextBoxCell headCell = new DataGridViewTextBoxCell();
                headCell.Value = record.WorkingHead.ToString("f6");
                headCell.Tag = true;

                row.Cells.Add(idCell);
                row.Cells.Add(flowCell);
                row.Cells.Add(presureInCell);
                row.Cells.Add(presureOutCell);
                row.Cells.Add(speedCell);
                row.Cells.Add(temperatureCell);
                row.Cells.Add(powerCell);
                row.Cells.Add(npshCell);
                row.Cells.Add(headCell);

                row.Tag = record;


                //this.experiment.RecordList.Add(record);
                this.dataGridView.Rows.Add(row);

            }
        }

        private void ViewForm_Load(object sender, EventArgs e)
        {
            LoadExperimentInfo();
            this.ChartDrawer.DrawChart(this.ChartData, this.userChart);
            //this.ChartDrawer.DrawChart(this.Service.CaculateChartData(this.Experiment), this.userChart);
        }
    }
}
